// SQLServerSession.cpp: implementation of the CSQLServerSession class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "AUSlotsTester.h"
#include "SQLServerSession.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CSQLServerSession::CSQLServerSession()
{

}

CSQLServerSession::~CSQLServerSession()
{

}

HRESULT CSQLServerSession::Open( LPCTSTR szServer, bool bUseIntegratedSecurity, LPCTSTR szUser, LPCTSTR szPassword, LPCTSTR szDatabase )
{
	USES_CONVERSION;

	HRESULT		hr;
	CDataSource db;
	CDBPropSet	dbinit(DBPROPSET_DBINIT);

	if ( bUseIntegratedSecurity )
	{
		dbinit.AddProperty(DBPROP_AUTH_INTEGRATED, OLESTR("SSPI"));
	}
	else
	{
		dbinit.AddProperty(DBPROP_AUTH_USERID, T2OLE( szUser ));
		dbinit.AddProperty(DBPROP_AUTH_PASSWORD, T2OLE( szPassword ));
	}

	dbinit.AddProperty(DBPROP_INIT_CATALOG, T2OLE( szDatabase ));
	dbinit.AddProperty(DBPROP_INIT_DATASOURCE, T2OLE( szServer ));
	dbinit.AddProperty(DBPROP_INIT_LCID, (long)1033);
	dbinit.AddProperty(DBPROP_INIT_PROMPT, (short)4);

	hr = db.Open(_T("SQLOLEDB.1"), &dbinit);
	if (FAILED(hr))
		return hr;

	return CSession::Open( db );
}
